namespace Vanilla.UI

import System

class Row (Box):
	def constructor (p as Box):
		super(p)
	
	def constructor (p as Box, f as bool):
		self(p)
		DrawFrame = f
	
	public UniformSizing as bool = false
	
	override MinSize as Size:
		get:
			return Size(2*Spacing, 2*Spacing) if Children == null
			w = Spacing
			h = Spacing*2
			for c in Children:
				w += c.MinSize.Width + Spacing
				h = System.Math.Max(h, c.MinSize.Height + 2*Spacing)
			return Size(w,h)
	
	override MaxSize as Size:
		get:
			if Expand:
				return Size(2*Spacing, 2*Spacing) if Children == null
				w = Spacing
				h = 10000.0
				for c in Children:
					w += c.MaxSize.Width + Spacing
					h = System.Math.Min(h, c.MaxSize.Height + 2*Spacing)
				return Size(w,h)
			else:
				return MinSize
	
	// ARRANGE
	override def Arrange ():
		min = MinSize
		max = MaxSize
		
		if UniformSizing:
			x = Spacing
			w = (Size.Width - Spacing - Spacing*Children.Length) / Children.Length
			for c in Children:
				c.Rect = Rect(x, Spacing, x + w, Size.Height-Spacing)
				x += w + Spacing
		else:
			ratio = (Size.Width - min.Width) / (max.Width - min.Width)
			ratio = 0 if double.IsNaN(ratio) or double.IsInfinity(ratio)
			//print "ratio=${ratio} size=${Size} min=${min} max=${max}"
			x = Spacing
			for c in Children:
				w = c.MinSize.Width + ((c.MaxSize.Width-c.MinSize.Width) * ratio)
				c.Rect = Rect(x, Spacing, x+w, Size.Height-Spacing)
				//print "c.Rect = ${c.Rect}"
				x += w + Spacing
